<?php
$cs = Yii::app()->getClientScript();
$cs->registerCssFile(Yii::app()->request->baseUrl.'/css/jquery-ui.css');
$cs->registerCssFile(Yii::app()->request->baseUrl.'/css/fileuploader.css');
$cs->registerCoreScript('jquery');
$cs->registerCoreScript('jquery.ui');
$cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/fileuploader.js');
$cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/ckeditor/ckeditor.js');
$cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/jquery-ui-timepicker-addon.js');

        $cs->registerScript('file-uploader-js',
	            'function onUploadComplete (id, fileName, responseJSON){
	                if (responseJSON.success)
	                {
	                    document.getElementById("Image_image").value = responseJSON.imgurl;
	                }
	            }
				
	            $(document).ready(function(){
	            
					$.get("getDetail", {type : $("#detailType").val()},
						function(result) {
							if(result.status === true) {
							$("#detailId").empty();
							$("#detailId").append("<option value=\"Select\">Select</option>");
							detailData = result.data;
							$.each(detailData, function(key, value){
							$("#detailId").append("<option value=\"" + key + "\">"+ value +"</option>");
					});
				}
			}, "json");

	                var uploader = new qq.FileUploader({
	                    element: document.getElementById("file-uploader"),
	                    action: "'.$this->createUrl('fileUpload/index').'",
	                    allowedExtensions: ["jpg", "jpeg", "png", "gif"],
	                    params: { sizeLimit: "500K" },
	                    onComplete: onUploadComplete
	                });

	                CKEDITOR.replace("Image_content", { toolbar : "AceBornToolbar", filebrowserUploadUrl: "'.$this->createUrl('fileUpload/ckeditor').'", width: "580px" });

	            });',
	        CClientScript::POS_END
	        );
?>
<script>
	function getDetailLabel()
	{
		$.get('getDetail', {type : $('#detailType').val()},
			function(result) {
				if(result.status === true) {
					$('#detailId').empty();
					$('#detailId').append('<option value="Select">Select</option>');
					detailData = result.data;
					$.each(detailData, function(key, value){
						$('#detailId').append('<option value="'+ key + '">'+ value +'</option>');
					});
				}
			}, "json");
	}
</script>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'image-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'Detail Type'); ?>
		<select onChange="getDetailLabel();" name="detailType" id="detailType">
			<option value="NEWS">NEWS</option>
			<option value="SERVICE">SERVICE</option>
		</select> 
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'Detail'); ?>
		<select name="detailId" id="detailId">
			<option value="Select">Select</option>
		</select> 
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>20,'maxlength'=>20)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'desc'); ?>
		<?php echo $form->textField($model,'desc',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'desc'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'image'); ?>
		<?php echo $form->textField($model,'image',array('size'=>50,'maxlength'=>50)); ?>
		<div id="file-uploader">
		 	<noscript>
				<p>Please enable JavaScript to use file uploader.</p>
			</noscript>
		</div>	
		<?php echo $form->error($model,'image'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'content'); ?>
		<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'content'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'photographer'); ?>
		<?php echo $form->textField($model,'photographer',array('size'=>20,'maxlength'=>20)); ?>
		<?php echo $form->error($model,'photographer'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'videographer'); ?>
		<?php echo $form->textField($model,'videographer',array('size'=>20,'maxlength'=>20)); ?>
		<?php echo $form->error($model,'videographer'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'markup_artist'); ?>
		<?php echo $form->textField($model,'markup_artist',array('size'=>20,'maxlength'=>20)); ?>
		<?php echo $form->error($model,'markup_artist'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'dress_designer'); ?>
		<?php echo $form->textField($model,'dress_designer',array('size'=>20,'maxlength'=>20)); ?>
		<?php echo $form->error($model,'dress_designer'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'director'); ?>
		<?php echo $form->textField($model,'director',array('size'=>20,'maxlength'=>20)); ?>
		<?php echo $form->error($model,'director'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'priority'); ?>
		<?php echo $form->textField($model,'priority',array('size'=>11,'maxlength'=>11)); ?>
		<?php echo $form->error($model,'priority'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
		<?php echo $form->dropDownList($model,'status', array('N' => Yii::t('core_msg', 'Hide'), 'Y' => Yii::t('core_msg', 'Show'))); ?>
		<?php echo $form->error($model,'status'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
